//author:kakake
class tsevaluationDao {
    public data = {
        dbConn: TSLobsterAPI.Program.GetDbConn(),
        WorkId: 1
    }

    constructor(workid: number) {
        this.data.WorkId = workid;
    }

    /**
     * 获取问诊记录
     */
    getmedrecord(id: number) {
        let strsql = "select * from WPMT_RegisteredPayment where Id=@id";
        return TSLobsterAPI.DbHelper.DbGetJsonObject(this.data.dbConn, strsql, { id: id });
    }

    /**
     * 获取评价
     */
    getevaluation(RecordId: number) {
        let strsql = "SELECT * FROM WPMT_DoctorEvaluation where RecordId=@RecordId";
        return TSLobsterAPI.DbHelper.DbGetJsonObject(this.data.dbConn, strsql, { RecordId: RecordId });
    }

    /**
     * 获取待处理评价
     */
    getevaluationpage(searchkey: string, status: number, pageInfo: any) {
        let strsql = "SELECT a.* FROM WPMT_DoctorEvaluation a \
                    where a.workid=@workid and a.DocName LIKE @searchkey and a.PatName like @searchkey";
        if (status != -1) {
            strsql += " and a.Status=@status";
        }

        let dbparam = {
            workid: this.data.WorkId,
            searchkey: '%' + searchkey + '%',
            status: status
        }

        return TSLobsterAPI.DbHelper.DbGetJsonData(this.data.dbConn, strsql, dbparam, pageInfo);
    }

    /**
     * 保存回复内容
     */
    savereplycontent(ID: any, ReplyContent: any) {
        let strsql = "update WPMT_DoctorEvaluation set ReplyContent=@ReplyContent,ReplyTime=GETDATE(),ReplyEmpId=@ReplyEmpId where ID=@ID";
        let dbparam = {
            ID: ID,
            ReplyContent: ReplyContent,
            ReplyEmpId: TSLobsterAPI.Program.GetSSOUserId()
        }

        TSLobsterAPI.DbHelper.DbExecuteUpdate(this.data.dbConn, strsql, dbparam);
    }

    /**
     * 发布，取消发布
     */
    stopevaluation(ID: any, status: any) {
        let strsql = "update WPMT_DoctorEvaluation set status=@status where ID=@ID";
        TSLobsterAPI.DbHelper.DbExecuteUpdate(this.data.dbConn, strsql, { ID: ID, status: status });
    }

    /**
     * 医生信息界面，显示点赞最多的评价
     */
    getevaluationtopone(doctId: any) {
        let strsql = "select top 1 * from WPMT_DoctorEvaluation where workid=@workid and status=1 and EmpId=@doctId order by givecount desc";
        return TSLobsterAPI.DbHelper.DbGetJsonData(this.data.dbConn, strsql, { workid: this.data.WorkId, doctId: doctId });
    }

    /**
     * 查询医生全部评价
     */
    getevaluationbydoctor(doctId: any, pageInfo: any) {
        let strsql = "select  * from WPMT_DoctorEvaluation where workid=@workid and status=1 and EmpId=@doctId";
        return TSLobsterAPI.DbHelper.DbGetJsonData(this.data.dbConn, strsql, { workid: this.data.WorkId, doctId: doctId }, pageInfo);
    }

    /**
     * 更新评价点赞数
     */
    updateevaluationgivecount(id: any) {
        let strsql = "update WPMT_DoctorEvaluation set givecount=isnull(givecount,0)+1 where ID=@id";
        TSLobsterAPI.DbHelper.DbExecuteUpdate(this.data.dbConn, strsql, { id: id });

        strsql="select givecount from WPMT_DoctorEvaluation where ID=@id";
        return TSLobsterAPI.DbHelper.DbExecuteQuery(this.data.dbConn,strsql,{id: id});
    }

}